import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class ClassManagement {
    private static List<String> classes = new ArrayList<>(); // 存储班级的列表

    // 新增班级
    public void addClass() {
        // 实现新增班级的逻辑
    }

    // 维护班级
    public void maintainClass() {
        // 实现维护班级的逻辑
    }

    // 班级列表
    public void listClasses() {
        // 实现获取班级列表的逻辑
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            createAndShowGUI();
        });
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("班级管理");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setSize(400, 300);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));
        frame.getContentPane().add(panel);

        JLabel label = new JLabel("班级管理功能", JLabel.CENTER);
        panel.add(label);

        JButton addClassButton = new JButton("新增班级");
        addClassButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String className = JOptionPane.showInputDialog(frame, "请输入班级名称:");
                if (className != null && !className.trim().isEmpty()) {
                    classes.add(className);
                    JOptionPane.showMessageDialog(frame, "班级添加成功: " + className);
                } else {
                    JOptionPane.showMessageDialog(frame, "班级名称不能为空");
                }
            }
        });
        panel.add(addClassButton);

        JButton maintainClassButton = new JButton("维护班级");
        maintainClassButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 实现维护班级的逻辑
                System.out.println("维护班级功能");
            }
        });
        panel.add(maintainClassButton);

        JButton listClassesButton = new JButton("班级列表");
        listClassesButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuilder classList = new StringBuilder();
                for (String c : classes) {
                    classList.append(c).append("\n");
                }
                JOptionPane.showMessageDialog(frame, classList.length() > 0 ? classList.toString() : "没有班级");
            }
        });
        panel.add(listClassesButton);

        frame.setVisible(true);
    }
}
